package buckets.core;

import java.util.Arrays;

/**
 * This simple class represents a state in a state space of a bucket filling problem.
 * 
 * @author vasek
 *
 */
public final class BucketState {

	private final int[] configuration;
	private BucketState predecessor;

	/**
	 * Constructor.
	 * 
	 * @param configuration of buckets
	 */
	public BucketState(final int[] configuration) {
		super();
		this.configuration = configuration;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Arrays.hashCode(configuration);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) { 			
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		
		BucketState other = (BucketState) obj;
		if (!Arrays.equals(configuration, other.configuration)) {
			return false;
		}
		
		return true;
	}
	
	/**
	 * @return this state's configuration
	 */
	public int[] getConfiguration() {
		return configuration;
	}

	@Override
	public String toString() {
		return Arrays.toString(configuration);
	}

	/**
	 * @param predecessor predecessor of this state in search space
	 */
	public void setPredecessor(final BucketState predecessor) {
		this.predecessor = predecessor;
	}	
	
	/**
	 * @return predecessor of this state in search space
	 */
	public BucketState getPredecessor() {
		return predecessor;
	}
	
		
}
